package xyz.soleperson

import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageByEntityEvent
import kotlin.math.ceil
import kotlin.math.min

class Events : Listener {
    @EventHandler
    fun onAttack(e: EntityDamageByEntityEvent) {
        if (e.damager is Player) {
            val player: Player = e.damager as Player
            val damage = ceil(e.damage).toInt()
            val rHealth = min(player.health + damage, 20.0).toInt()
            val level : Int = ceil(damage / 10.0).toInt()

            player.health = rHealth.toDouble()
            player.level = player.level + level

            player.sendMessage("伤害: $damage, 血量 +${20 - rHealth}, 等级 +$level")
        }
    }
}
